<?php
/**
 * 
 * @author szm
 *
 */
class Vocabulary_model  extends CI_Model  {
    public function __construct(){
        parent::__construct();
        $this->load->database();
    }
    /**
     * delete
     * @param mixed $lessonIds
     * @return Array
     */
    public function getSentenceVocabularies($lessonIds){
        if(empty($lessonIds)){
            return false;
        }
        if(!is_array($lessonIds)){
            $lessonIds=array($lessonIds);
        }
        $lessonIds=implode(",",$lessonIds);
		try{
	        $this->db->select('g.*,ss.sample_sentence_id');
	        $this->db->from('glossary as g');
	        $this->db->join('Sentence_Glossary  as sc','g.glossary_id = sc.glossary_id','left');
	        $this->db->join('Sample_Sentences	as ss','ss.sample_sentence_id=sc.sample_sentence_id','left');
	        $this->db->where_in('ss.lesson_id',$lessonIds);
	        $result=$this->db->get();
			$rs=$result->result_array();
			//fb::dump();
			//var_dump($rs);die;
			return $rs;
		}catch(Exception $e){
			return array();
		}
    }
    
    public function getAllItems($lessonId){
    	if(empty($lessonId)){
    		return false;
    	}
    	$this->db->select('dic.*');
    	$this->db->from('zh_jp_dictionary as dic');
    	$this->db->join('sentence as st','st.sentence_id =dic.sentence_id','left');
		$this->db->where('st.lesson_id',$lessonId);
		$result=$this->db->get();
		$rs=$result->result_array();
		return $rs;
    	
    }
    /**
     * deleted
     * @param $lessonIds
     */
    public function getVocabulariesbk($lessonIds){
        if(empty($lessonIds)){
            return false;
        }
        if(!is_array($lessonIds)){
            $lessonIds=array($lessonIds);
        }
        $lessonIds=implode(",",$lessonIds);
        $this->db->select('g.*');
        $this->db->from('glossary as g');
        $this->db->join('Sentence_Glossary as sg','sg.glossary_id=g.glossary_id','left');
        $this->db->join('Sample_Sentences as ss','ss.sample_sentence_id=sg.sample_sentence_id','left');
        $this->db->where_in('ss.lesson_id',$lessonIds);
        $sql="select g.* from glossary as g
        	left join Sentence_Glossary as sg on sg.glossary_id=g.glossary_id
			left join Sample_Sentences as ss on ss.sample_sentence_id=sg.sample_sentence_id
			where ss.lesson_id in ($lessonIds)";

        fb::dump('getVocabularies_sql',$sql);
	     try{
            $dbSource=$this->db->query($sql);
            $resultArr=$dbSource->result_array();
            fb::dump('getVocabularies_array',$resultArr);
            return $resultArr;
	     }catch(Exception $e){
            return $sql;
         }
    }
    public function listAllVocabularys(){
        $data=array();
        $this->load->view('list_all_vocabularys');
    }
    
    public function getVocabulary(){
        $data=array();
        $this->load->view('Vocabulary');
    }
    
    public function saveVocabulary(){
        $data=array();
        redirect('/lesson/index/', 'refresh');

    }
    
    public function removeVocabulary(){
        $data=array();
        redirect('/lesson/index/', 'refresh');
    }
}

